/**
  ******************************************************************************
  * @file    FaultIndication.h
  * @author  MIJI
  * @version V0.0.1
  * @date    16-06-2016 
  * @brief   This file contains all the fault report function
  *				 
  *          
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; KION(SZ) R&D Center
  *
  * Licensed under KION, (the "License");
  *
  ******************************************************************************
  */

#ifndef __FAULTINDICATION_H_
#define __FAULTINDICATION_H_
/* Includes ------------------------------------------------------------------*/

#include "stm32f10x.h"
#include "global.h"
#include "top.h"
#include "var_tbl.h"


#define FAULT_QUEUE_SIZE 15
#define FAULT_QUEUE_ENTER_CRITICAL
#define FAULT_QUEUE_EXIT_CRITICAL


#define ACK_BIT            BIT0
#define CLR_BIT            BIT1
#define SHOW_BIT           BIT2

typedef struct
{
  u32 faultCode1;
  u32 faultCode2;
  u8  errText1;
  u8  errText2;
  u8 attr;
  u8 fault_index;
  FaultPreActionFunc faultPreAckAction;
  FaultActionFunc faultAckAction;
}FaultQueueElement_t;

typedef struct 
{
  FaultQueueElement_t element[FAULT_QUEUE_SIZE];
  FaultQueueElement_t * pFQIn;
  FaultQueueElement_t * pFQOut;
}FaultQueue_t;


extern FaultQueue_t FaultQueue;
extern FaultQueue_t FaultOutputQueue;
extern FaultQueueElement_t SingleFault;


void FaultQueueInit(FaultQueue_t * queue);
u8 FaultQueueAppend(FaultQueue_t * queue, u32 faultcode1, u32 faultcode2, u8 text1_index1, u8 text2_index, u8 fault_index, FaultPreActionFunc faultPreAction, FaultActionFunc faultAction);
u8 FaultUpdateSingle(FaultQueueElement_t * fault, u32 faultcode1, u32 faultcode2, u8 text1_index1, u8  text2_index);
FaultQueueElement_t * FaultQueueGetLast(FaultQueue_t * queue);
u8 FaultQueueRemoveLast(FaultQueue_t * queue);
u8 FaultShow(void);
void FaultPreAckActionIdle(void);
void FaultAckActionIdle(u8 fault_index);
void FaultQueueRemoveItem(FaultQueue_t * queue, u32 faultcode1, u32 faultcode2, u8  text1, u8  text2);
void FaultSingleQueueRemoveItem(FaultQueueElement_t * fault);


#endif

